package org.barad.architecture.analyzer.widgets;

import java.net.URL;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;

import org.barad.architecture.analyzer.archpad.xml.handler.ComponentDescriptor;

public class ArchPadButton extends JButton {
	public static final long serialVersionUID = 1L;
	private ComponentDescriptor componentDescriptor;
	private boolean createTransferable;
	private String iconFileName;

	public ArchPadButton(ComponentDescriptor componentDescriptor, boolean createTransferable) {
		this.componentDescriptor = componentDescriptor;
		this.createTransferable = createTransferable;
		this.iconFileName = componentDescriptor.getIconName();
		super.setIcon(createIcon());
	}
	
	public ArchPadButton(String iconFileName, boolean createTransferable) {
		this.createTransferable = createTransferable;
		this.iconFileName = iconFileName;
		super.setIcon(createIcon());
	}
	
	private Icon createIcon() {
		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
		URL url = classLoader.getResource(iconFileName);
		return new ImageIcon(url);
	}

	public ComponentDescriptor getComponentDescriptor() {
		return componentDescriptor;
	}

	public boolean isCreateTransferable() {
		return createTransferable;
	}
	
	public String getIconFileName() {
		return iconFileName;
	}

	public void setIconFileName(String iconFileName) {
		this.iconFileName = iconFileName;
	}
}
